﻿using GUI.RLAServiceReference;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GUI.Tabpages
{
    /// <summary>
    /// Interaction logic for PageAchievementList.xaml
    /// </summary>
    public partial class PageAchievementList : Page
    {
        private IRealLifeService _rlService;
        private List<Achievement> _achievements;
        private User _user;

        public PageAchievementList(User user)
        {
            _user = user;
            _rlService = new RealLifeServiceClient();
            InitializeComponent();
            UpdateList(user);
        }

        public void UpdateList(User user)
        {
            var userAchList = _rlService.GetUserAchievements(user);
            _achievements = (from x in userAchList select x.Achievement).ToList();

            LvAchievements.ItemsSource = userAchList; //achievements;
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateList(_user);
        }

        private void LvAchievements_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            UserAchievement userAch = _rlService.GetUserAchievements(_user).
                SingleOrDefault(x => x.Achievement.AchievementId ==
                    ((UserAchievement)LvAchievements.SelectedItem).Achievement.AchievementId);

            var UIAchPopup = new UIUserAchievementPopUp(userAch);
            UIAchPopup.Show();
        }
    }
}